//
//  Userservice.swift
//  Twitter
//
//  Created by Hoa.wang on 2022/4/7.
//

import ParseSwift

struct UserService {
    
    func fetchUser(withUid uid: String, completion: @escaping (User) -> Void)  {
        let query = User.query("objectId" == uid)
        query.first { results in
            switch results {
            case .success(let user):
                completion(user)
            case .failure(let error):
                print("DEBUG: Failed to query with error: \(error.localizedDescription)")
                
            }
        }
    }
    
    func fetchUsers(completion: @escaping ([User]) -> Void) {
        
        let query = User.query()
        query.find { results in
            switch results {
            case .success(let users):
                completion(users)
            case .failure(let error):
                print("DEBUG: Failed to query with error: \(error.localizedDescription)")
                
            }
        }
    }
    
}
